package com.student.Activitys.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.student.Activitys.R;
import com.student.Activitys.activity.base.BaseActivity;
import com.student.Activitys.bean.LeaveDetailsBean;
import com.student.Activitys.bean.ScheduleWeekBean;
import com.odd.Activitys.http.manager.ScheduleManager;
import com.student.Activitys.utils.Constant;
import com.student.Activitys.utils.DataUtils;

import org.simple.eventbus.Subscriber;

import butterknife.Bind;

/**
 * 项目名称：智慧校园学生端
 * 类描述：请假详情页面
 * 创建人：张飞祥
 * 创建时间：2017/9/29 16:05
 * 修改人：张飞祥
 * 修改时间：2017/9/29 16:05
 * 修改备注：
 */
public class LeaveDetailsActivity extends BaseActivity {
    @Bind(R.id.iv_return)
    ImageView ivReturn;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_leave_details_style)
    TextView tvLeaveDetailsStyle;
    @Bind(R.id.tv_leave_details_course)
    TextView tvLeaveDetailsCourse;
    @Bind(R.id.tv_leave_details_time)
    TextView tvLeaveDetailsTime;
    @Bind(R.id.tv_leave_details_teacher)
    TextView tvLeaveDetailsTeacher;
    @Bind(R.id.tv_leave_details_reason)
    TextView tvLeaveDetailsReason;

    //上课周次
    public String skzc = "";

    //传递过来的课节 实体对象
    ScheduleWeekBean bean = null;
    //初始化网络请求
    public ScheduleManager mApiManager;
    @Override
    protected void initUI() {
        //初始化布局
        setContentView(R.layout.act_leave_details);
        //设置标题
        tvTitle.setText("请假详情");
        //显示返回按钮
        ivReturn.setVisibility(View.VISIBLE);
        //网络请求接口 常驻方法
        mApiManager = mApiManager.getScheduleApiManager(LeaveDetailsActivity.this, LeaveDetailsActivity.this.getTaskId());
        // 获取传递过来的封了数据的Bundle
        Bundle bundle = this.getIntent().getExtras();
        // 获取 传递过来的 实体 数据
        bean = bundle.getParcelable(Constant.SCHEDULE_WEEK_BEAN);
        // 获取上课周次
        skzc = bundle.getString(Constant.SKZC);
    }

    @Override
    protected void initData() {
        //http 数据加载
        initViewRefresh();
        //退出
        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void getNotData() {

    }

    //初始化加载 数据
    private void initViewRefresh() {
        //显示 加载dialog
        initShowTimeDialog("正在加载当前请假详情数据，请稍后...",LeaveDetailsActivity.this);
        //网络请求 请假详情数据
        mApiManager.scheduleDayLeaveDetails(Constant.HTTP_DAY_LEAVE_DETAILS, xh,bean.getKCH(),bean.getSKJC(),bean.getSKXQ(),skzc,bean.getXNXQ());
    }


    /**
     * 日课表 请假详情 网络请求 加载是否成功
     */
    @Subscriber(tag = Constant.BUS_DAY_LEAVE_DETAILS_ON_COMPLETED)
    public void initAddress(String str) {
        //销毁handler
        time_handler.removeCallbacks(time_runnable);
        timeDailog.dismiss();
        dialog.dismiss();
    }
    /**
     * 日课表 请假详情 网络请求 返回具体 数据实体
     */
    @Subscriber(tag = Constant.BUS_DAY_LEAVE_DETAILS_LIST)
    public void initAddress(final LeaveDetailsBean leaveDetails) {
        //请假类型
        tvLeaveDetailsStyle.setText(leaveDetails.getQJLX());
        //课程名
        tvLeaveDetailsCourse.setText(leaveDetails.getKCM());
        //请假时间
        tvLeaveDetailsTime.setText(DataUtils.getNowDate("yyyy/MM/dd") + "（" + leaveDetails.getSKJC().substring(0,2) + "," + leaveDetails.getSKJC().substring(2, 4) + " 节）");
        //上课老师
        tvLeaveDetailsTeacher.setText(leaveDetails.getTeacherName());
        //请假原因
        tvLeaveDetailsReason.setText(leaveDetails.getQJLY());
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        //刷新当前页面
        if (falg) {
            timeSecond = 10;
            initViewRefresh();
            falg = false;
        }
    }
}
